/*
 *  utf8.c
 *
 *  utf8
 *
 *  Copyright (C) 2008  Huang Guan
 *
 *  2008-7-10 13:31:57 Created.
 *
 *  Description: This file mainly includes the functions about 
 *  utf8
 *
 */


#include <iconv.h>


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "qqdef.hpp"
#include "debug.hpp"
#include "memory.hpp"
#include "config.hpp"
#include "utf8.hpp"



void utf8_to_gb( char* src, char* dst, int len )
{
	int ret = 0;
	uint inlen = strlen( src );
	uint outlen = len;
#ifdef __linux__
    char* inbuf = src;
#else
    const char* inbuf = src;
#endif
	char* outbuf = dst;
	iconv_t cd;
	cd = iconv_open( "GBK", "UTF-8" );
	if ( cd != (iconv_t)-1 ){
		ret = iconv( cd, &inbuf, &inlen, &outbuf, &outlen );
                //if( ret != 0 )
        //DBG("iconv failed err: %s\n", strerror(errno) );
		iconv_close( cd );
	}
}
void gb_to_utf8( char* src, char* dst, int len )
{
	int ret = 0;
	uint inlen = strlen( src );
	uint outlen = len;
#ifdef __linux__
    char* inbuf = src;
#else
    const char* inbuf = src;
#endif
	char* outbuf = dst;
	iconv_t cd;
	cd = iconv_open( "UTF-8", "GBK" );
	if ( cd != (iconv_t)-1 ){
		ret = iconv( cd, &inbuf, &inlen, &outbuf, &outlen );
                //if( ret != 0 )
            //DBG("iconv failed err: %s\n", strerror(errno) );
		iconv_close( cd );
	}
}


